import { storeToRefs } from 'pinia'
import diocmApi from '@/api/diocmApi'
import examStore from '@/store/exam/index'
import { Ref, ref } from 'vue'
import { AxiosResponse } from 'axios'

interface ImageBacks {
  body: any
  buf2: any
  comment: string
  fOrderBy: string
  flag: string
  imageId: string
  imageUri: string
  import: any
}

interface ExamDetail {
  age: number
  ageUnit: string
  clinicDiagnosis: null
  describes: string
  diagnosis: string
  examDate: string
  examMethod: string
  examTime: string
  filter1: string
  filter2: string
  fromDeptName: string
  fromDocName: string
  id: string
  imageBacks: ImageBacks[]
  inPatientNo: string
  isFinished: string
  machineName: string
  machineType: string
  moduleName: string
  name: string
  nation: string
  oldDocID: string
  operatorName: string
  outFlg: string
  outPatientNo: string
  patientID: string
  pdfPath: string
  phone: string
  reportDoctor: string
  resultisPlus: string
  sex: string
  sickBedNo: string
  submitTime: string
  viscGroup: string
  visceras: string
}

class ExamDetailServer {
  static examDetailServer: ExamDetailServer = new ExamDetailServer()
  static store = examStore()
  static storeRef = storeToRefs(ExamDetailServer.store)
  static examDetail: Ref<ExamDetail | null> = ref(null)

  static async findExamDetail() {
    const length = window.location.href.split('/').length
    const id = window.location.href.split('/')[length - 1] + '.json'
    const moduleName = window.location.href.split('/')[length - 2]
    const data: AxiosResponse<ExamDetail> = await diocmApi.findExamDetail(
      moduleName,
      id
    )
    ExamDetailServer.examDetail.value = data.data
    console.log(ExamDetailServer.examDetail.value)
  }
}

export default ExamDetailServer
